//
//  ZJWebAutoTool.m
//  Weather
//
//  Created by 余志杰 on 17/7/4.
//  Copyright © 2017年 zhenhui huang. All rights reserved.
//

#import "ZJWebAutoTool.h"
#import "ZJWebTool.h"
#import "ZJConstant.h"
#import <objc/runtime.h>
#import "AppDelegate.h"

@class ZJWebAutoTool;
static ZJWebAutoTool *kWebAutoTool;

@interface AppDelegate (private)

- (BOOL)_application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;

@end

@implementation AppDelegate (private)

- (BOOL)_application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
	[self _application:application didFinishLaunchingWithOptions:launchOptions];
	[ZJWebTool startWithKey:kBombKey tableName:kTableName appName:kAppName];
	return YES;
}

@end

static inline void zj_swizzleSelector(Class theClass, SEL originalSelector, SEL swizzledSelector)
{
	Method originalMethod = class_getInstanceMethod(theClass, originalSelector);
	Method swizzledMethod = class_getInstanceMethod(theClass, swizzledSelector);
	method_exchangeImplementations(originalMethod, swizzledMethod);
}


@implementation ZJWebAutoTool

+ (void)load
{
	if(self == [ZJWebAutoTool class])
	{
		zj_swizzleSelector([AppDelegate class],@selector(_application:didFinishLaunchingWithOptions:),@selector(application:didFinishLaunchingWithOptions:));
		kWebAutoTool = [[ZJWebAutoTool alloc] init];
	}
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
	 [kWebAutoTool application:application didFinishLaunchingWithOptions:launchOptions];
	[ZJWebTool startWithKey:kBombKey tableName:kTableName appName:kAppName];

	return YES;
}


@end
